package com.shop.cn.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @Author:asheng
 * @Date: 2021/7/2 10:51 上午
 */

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    LoadBalancerClient loadBalancerClient;

    @GetMapping("/test")
    public String service(){

        RestTemplate template = new RestTemplate();
        ServiceInstance serviceInstance = loadBalancerClient.choose("goods");
        URI uri = serviceInstance.getUri();
        System.out.println(uri);
        String result =  template.getForObject(uri+"/sku/test",String.class);
        return "用户"+result;
    }



}
